package service

import (
	"singo/model"
	"singo/serializer"
)

// TaskCheckService 待审核已审核管理列表服务
type TaskCheckService struct {
	ID    string  `form:"id" json:"id" binding:"required"`
	Score float64 `form:"score" json:"score"`
}

// TaskCheckList 待审核已审核管理列表
func (service *TaskCheckService) TaskCheck() serializer.Response {
	task := model.Task{}
	err := model.DB.First(&task, "uid = ?", service.ID).Error
	if err != nil {
		return serializer.Response{
			Status: 404,
			Msg:    "不存在",
			Error:  err.Error(),
		}
	}

	if err = model.DB.Model(&task).Where("uid = ?", service.ID).Updates(model.Task{ReviewStatus: 1, Score: service.Score}).Error; err != nil {
		return serializer.Response{
			Status: 50002,
			Msg:    "更新失败",
			Error:  err.Error(),
		}
	}

	return serializer.Response{
		Data:   true,
		Msg:    "成功",
		Status: 0,
	}
}
